/**
 * @brief Implementation of the algorithm to build the behavior tree from the plan tree
 * @date 2024-2-27
*/

#ifndef __CONT_BT_BUILDER_HPP__
#define __CONT_BT_BUILDER_HPP__

#include "contbtsys_core/contbtsys_ds.hpp"
#include "contbtsys_core/ContPlanSolverBase.hpp"
#include "contbtsys_core/Utils.hpp"

namespace ContBTSys {
    /**
     * @brief Build the behavior tree from the plan tree
    */
    class ContBTBuilder {
    public:
        ContBTBuilder(ContPlannerBase::ContPlannerBasePtr planner) {
            cont_planner_ptr_ = planner;
        }
        ~ContBTBuilder() {}

        /**
         * @brief Build the behavior tree from the plan tree, export the tree using xml format similar to BehaviorTree.CPP
         * @param domain The path of domain file
         * @param problem The path of problem file
         * @param node_namespace The namespace of the node, default is ""
        */
        std::string getBT(
            const std::string & domain, const std::string & problem,
            const std::string & node_namespace = ""
        );

    protected:
        /**
         * @brief indent level of "\t" to the right.
        */
        std::string t(int level);

        /**
         * @brief Build the behavior tree from an action node of plan tree traversely, export the tree using xml format similar to BehaviorTree.CPP
         * @param action_node a node from the plan tree generated by a contingent planner, which is transformed into the data structure in "contbtsys_core/contbtsys_ds.hpp".
         * @param level the level of the node in the xml file.
        */
        std::string buildBT(
            ActionPtr action_node, int level
        );

    
    private:
        ContPlannerBase::ContPlannerBasePtr cont_planner_ptr_;
    };
}   // namespace ContBTSys

#endif